import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vuesetupExtend from 'vite-plugin-vue-setup-extend'
import {resolve} from 'path'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import inject from '@rollup/plugin-inject'

// https://vitejs.dev/config/
export default defineConfig({
  resolve: {
    alias: {
      '@': resolve(__dirname, 'src')
    }
  },
  plugins: [
    vue(),
    vuesetupExtend(), // 解决组件中script使用setup时设置组件name值
    AutoImport({ // elementplus按需加载插件
      resolvers: [ElementPlusResolver()]
    }),
    Components({ // elementplus按需加载插件
      resolvers: [ElementPlusResolver()]
    }),
    inject({
      $: 'jquery', // 这里会自动载入 node_modules 中的 jquery
      jQuery: 'jquery',
      "windows.jQuery": "jquery"
    })
  ],
  server: {
    host: true,
    open: true,
    port: 9999,
    // proxy: {
    //   '/api': {
    //     target: 'http://172.16.70.14:8087',
    //     changeOrigin: true,
    //     ws: true, // 允许websocket代理
    //     rewrite: (path) => path.replace(/^\/api/, '')
    //   }
    // }
  }
})
